package net.mingsoft.basic.aop;

import org.slf4j.*;
import org.aspectj.lang.reflect.*;
import com.mchange.v1.util.*;
import org.springframework.web.bind.annotation.*;
import org.aspectj.lang.*;
import java.lang.reflect.*;
import java.lang.annotation.*;

public abstract class BaseAop
{
    protected final Logger LOG;
    
    public BaseAop() {
        this.LOG = LoggerFactory.getLogger((Class)this.getClass());
    }
    
    protected final <T> T getType(final JoinPoint jp, final Class<T> clazz) {
        final Object[] args;
        final Object[] objs = args = jp.getArgs();
        for (final Object obj : args) {
            if (obj != null && obj.getClass() == clazz) {
                return (T)obj;
            }
        }
        return null;
    }
    
    protected final <T> T getType(final JoinPoint jp, final Class<T> clazz, final boolean hasParent) {
        final Object[] args;
        final Object[] objs = args = jp.getArgs();
        for (final Object obj : args) {
            if (obj != null && (obj.getClass() == clazz || obj.getClass().getSuperclass() == clazz)) {
                return (T)obj;
            }
        }
        return null;
    }
    
    protected final Object getJsonParam(final JoinPoint jp) {
        final Signature signature = jp.getSignature();
        final MethodSignature methodSignature = (MethodSignature)signature;
        final Method method = methodSignature.getMethod();
        final Annotation[][] parameterAnnotations2;
        final Annotation[][] parameterAnnotations = parameterAnnotations2 = method.getParameterAnnotations();
        for (final Annotation[] parameterAnnotation : parameterAnnotations2) {
            final int paramIndex = ArrayUtils.indexOf((Object[])parameterAnnotations, (Object)parameterAnnotation);
            for (final Annotation annotation : parameterAnnotation) {
                if (annotation instanceof RequestBody) {
                    return jp.getArgs()[paramIndex];
                }
            }
        }
        return null;
    }
    
    protected final <T extends Annotation> T getAnnotation(final JoinPoint jp, final Class<T> an) {
        final Signature signature = jp.getSignature();
        final MethodSignature methodSignature = (MethodSignature)signature;
        final Method method = methodSignature.getMethod();
        if (method != null) {
            return method.getAnnotation(an);
        }
        return null;
    }
}
